import { PageData, PageDto } from "~/rest";

import { getGateway, Gateway } from "@/droplet-bus/core.define";
import { User } from "@/stream-user/schema.user";
import { app_gateway, BookQuery, BookQueryCache } from "@/pond-book/core.define";
import { BookContactMap } from "@/pond-book/schema.book";

export const BookDefaultGateway: Gateway = getGateway(app_gateway, "pond_book_default");

export const BookMapGateway: Gateway = getGateway(app_gateway, "pond_book_map");
export type getBookMapStatMonthDto = {
  tradeYear: number;
  tradeMonth: number;
  tradeScope: string;
  query: BookQuery[];
};
export type getBookMapListDto = {
  tradeYear: number;
  tradeMonth: number;
  tradeScope: string;
  query: BookQuery[];
};

export const BookContactMapGateway: Gateway = getGateway(app_gateway, "pond_book_contact_map");
export type getBookContactListDto = PageDto<BookContactMap>;

export interface BookInterfaceWithDerive<T> {
  /** 剩余账簿计算任务 */
  getTask(dto: T): Promise<{ count: number }>;

  /** 统计指定月份的明细账 */
  getBookMapStatMonth(dto: T & getBookMapStatMonthDto): Promise<BookQueryCache>;

  /** 指定月份，查看全部开单人的各种明细账 */
  getBookMapList(dto: T & getBookMapListDto): Promise<(BookQueryCache & { justCreator: User })[]>;

  /** 指定月份，对指定明细账进行排序（携带联系人信息）*/
  getBookContactList(dto: T & getBookContactListDto): Promise<PageData<BookContactMap>>;
}
